package com.jgp.timing.service;


import com.jgp.security.secmodel.AdminUser;
import com.jgp.security.secrepository.AdminUserRepository;
import com.jgp.test.PersistTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 项目   jgp-cloud-parent
 * 作者   loufei
 * 时间   2019/3/31
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {PersistTest.class})
public class JobActionServiceTest {
    
    @Resource
    private AdminUserRepository repository;
    
    @Test
    public void create() {
        AdminUser adminUser = new AdminUser();
        adminUser.setUsername("loufei1");
        adminUser.setEmail("775674502@qq.com");
        adminUser.setTel("18562183371");
        repository.create(adminUser);
    }
    
    @Test
    public void createInBatch() {
        List<AdminUser> ms = new ArrayList<>();
        for (long i=0;i<10;i++){
            AdminUser adminUser = new AdminUser();
            adminUser.setUsername("loufei"+i);
            adminUser.setEmail("775674502@qq.com");
            adminUser.setTel("18562183371");
            ms.add(adminUser);
        }
        repository.createInBatch(ms);
    }
    
    @Test
    public void update() throws InterruptedException {
        AdminUser adminUser = new AdminUser();
        adminUser.setId("d1e4badda1324a91b83305f8602e766c");
        adminUser.setUsername("loufei1");
        adminUser.setEmail("775674522@qq.com");
        adminUser.setTel("18562183372");
        repository.update(adminUser);
    }
    
    @Test
    public void updateInBatch() {
        List<String> ids = new ArrayList<>();
        ids.add("450545246d3b456d98accf074e36cf56");
        ids.add("664a04f5ddab42318788147ebefa9588");
        ids.add("46a769cef0624b3cabaee86dd7a2b82b");
        List<AdminUser> ms =  ids.stream().map(id -> {
            AdminUser adminUser = new AdminUser();
            adminUser.setId(id);
            adminUser.setUsername("xx2x");
            return adminUser;
        }).collect(Collectors.toList());
        repository.updateInBatch(ms);
    }
}